package com.junqson.je.recruit.service;

import com.alibaba.fastjson.JSON;
import com.junqson.je.recruit.model.dto.MessageDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @Descriptions
 * @Company
 * @Author Junqson
 * @Date 2020/3/7 20:53
 * @Version 1.0
 */
@Slf4j
@Service
public class MsgService {

    @Autowired
    private StringRedisTemplate redisTemplate;


    private static final String OUT_MSG_CHANNEL = "out_msg";

    public void sendMsg(MessageDTO messageDTO) {
        String str = JSON.toJSONString(messageDTO);
        try {
            redisTemplate.convertAndSend(OUT_MSG_CHANNEL, str);
            log.info("发送消息成功, msg = [{}]", str);
        } catch (Exception e) {
            log.error("发送消息失败, msg = [{}]", str);
        }
    }

}
